package apps.AfterDlcs.afterDlcsBL.city;

import apps.AfterDlcs.AfterDlcs;
import apps.AfterDlcs.afterDlcsBL.Keys;
import backs.dataBase.DBNormal;

public class CityBL
{
    public static int getCityPopulation(int group,int cityID)
    {
        return Integer.parseInt(getCityValue(group,cityID, Keys.NOW_POPULATION,"0",true));
    }

    public static int getCityMaxPopulation(int group,int cityID)
    {
        return Integer.parseInt(getCityValue(group,cityID,Keys.MAX_POPULATION,"2",true));
    }

    public static int getCityLastPopulation(int group,int cityID)
    {
        return getCityMaxPopulation(group,cityID)-getCityPopulation(group,cityID);
    }

    public static String getCityValue(int group,int cityID,String key)
    {
        return getCityValue(group,cityID,key,null,false);
    }

    public static String getCityValue(int group,int cityID,String key,String defaultValue,boolean reset)
    {
        if(reset)
            return DBNormal.getValue(AfterDlcs.dbName, group, "city_" + cityID + "_" + key, defaultValue, reset);
        else
        {
            String out=DBNormal.getValue(AfterDlcs.dbName, group, "city_" + cityID + "_" + key);
            if(out==null&&defaultValue!=null) return defaultValue;
            return out;
        }
    }

    public static void setCityValue(int group,int cityID,String key,String value)
    {
        DBNormal.setValue(AfterDlcs.dbName, group, "city_" + cityID +"_"+ key, value,true);
    }
}
